from typing import *


class Solution:
    def isMonotonic(self, nums: List[int]) -> bool:
        if len(nums) < 3:
            return True
        for i in range(len(nums) - 2, -1, -1):
            nums[i + 1] = nums[i] - nums[i + 1]
        a = 0
        for i in range(1, len(nums)):
            if nums[i] > 0:
                if a == 0:
                    a = 1
                if a < 0:
                    return False
            elif nums[i] < 0:
                if a == 0:
                    a = -1
                if a > 0:
                    return False
        return True
